/**
 * Copyright (c) Software Institute of PKU
 * All rights reserved. 
 * This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 */
package edu.pku.sei.modeler.figures;

import org.eclipse.draw2d.ColorConstants;
import org.eclipse.draw2d.Graphics;
import org.eclipse.draw2d.PositionConstants;
import org.eclipse.draw2d.XYLayout;
import org.eclipse.draw2d.geometry.Dimension;
import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.draw2d.text.FlowPage;
import org.eclipse.draw2d.text.TextFlow;
import org.eclipse.swt.graphics.Color;

import edu.pku.sei.modeler.uml.ResourceFactory;
import edu.pku.sei.modeler.uml.test.FragmentBorder;

/**
 * @generated
 * 
 */
public class CombinedFragmentFigure extends CommonFigure {
	private FlowPage titleFlow;

	private TextFlow stereotypes;

	private TextFlow op;

	public CombinedFragmentFigure(String operator) {
		setLayoutManager(new XYLayout());
		setBorder(new FragmentBorder());
		stereotypes = new TextFlow("");
		op = new TextFlow();
		op.setFont(ResourceFactory.getHeadFont());
		op.setText(operator);
		titleFlow = new FlowPage();
		titleFlow.setHorizontalAligment(PositionConstants.CENTER);
		titleFlow.add(stereotypes);
		titleFlow.add(new TextFlow("   "));
		titleFlow.add(op);
		titleFlow.setOpaque(false);
		add(titleFlow);
	}

	public void changeLineColor(Color color) {
		((FragmentBorder)this.getBorder()).setColor(color);
	}
	
//	@Override
	protected void paintFigure(Graphics graphics) {
//		// ((FragmentBorder) getBorder()).setColor(this.getBorderColor());
//		((FragmentBorder) getBorder()).setBackgroundColor(this
//				.getBackgroundColor());
//		((FragmentBorder) getBorder()).paintLabelBackground(this, graphics);
//		titleFlow.setFont(this.getFont());
//		// titleFlow.setForegroundColor(this.getFontColor());
		titleFlow.setFont(ResourceFactory.getHeadFont());
		titleFlow.setForegroundColor(ColorConstants.black);
		this.setOpaque(false);
	}

	@Override
	public void validate() {
		if (isValid())
			return;
		super.validate();

		Dimension prefSize = titleFlow.getPreferredSize();
		if (!titleFlow.getSize().equals(prefSize)) {
			titleFlow.setSize(prefSize);
		}
	}

	public Rectangle getLocalTextBounds() {
		return op.getBounds().getCopy();
	}
	
	
	 public void setLabel(String labelText) {
	        op.setText(labelText);
	        repaint();
	    }
}
